package com.browsesoft.baseadapter;

import java.lang.reflect.Constructor;

import com.browsesoft.PropertiesService;

/**
 * BlobEntity工厂
 * 
 * @author Administrator
 * 
 */
public class BlobEntityFactory {
	/**
	 * 单例
	 */
	private static BlobEntityFactory instance = new BlobEntityFactory();

	private BlobEntityFactory() {
	}

	public static BlobEntityFactory getInstance() {
		return instance;
	}

	/**
	 * 生成新的blob实体
	 */
	public BlobEntity newBlobEntity() {
		// 从属性文件里得到类，产生对象
		try {
			String cname = PropertiesService.getProperty("blob", "class");
			return (BlobEntity) Class.forName(cname).newInstance();
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 根据Id号得到新的blob实体
	 */
	public BlobEntity getBlobEntity(String id) {
		// 从属性文件里得到类，得到含一个字符串参数的构造函数，调用之
		try {
			String cname = PropertiesService.getProperty("blob", "class");
			Class c = Class.forName(cname);
			Constructor cons = c.getConstructor(new Class[] { String.class });
			return (BlobEntity) cons.newInstance(new Object[] { id });
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
}
